# Author    :Dun_Hz
# Time      :2024/3/14 20:37
# 二叉树的遍历

#实现树的结构
class Node():
    def __init__(self, data):
        self.data = data
        self.left = None
        self.right = None
    def pre_traverse(self, node):
        if node:
            print(node.data, end='')
            self.pre_traverse(node.left)
            self.pre_traverse(node.right)
    def in_traverse(self, node):
        if node:
            self.in_traverse(node.left)
            print(node.data, end='')
            self.in_traverse(node.right)
    def post_traverse(self, node):
        if node:
            self.post_traverse(node.left)
            self.post_traverse(node.right)
            print(node.data, end='')
if __name__ == '__main__':
    # 实例化节点
    A = Node('a')
    B = Node('b')
    C = Node('c')
    D = Node('d')
    E = Node('e')
    F = Node('f')
    A.left = B
    A.right = C
    B.left = D
    B.right = E
    C.left = F
    A.pre_traverse(A)
    print('')
    A.in_traverse(A)
    print('')
    A.post_traverse(A)
